package com.tedu.Test;

import java.util.ArrayList;
import java.util.Arrays;

//对象数组
public class T1 {
    public static void main(String[] args) {
        Person[] arr=new Person[3];//数组 存放Person类型

        Person one=new Person("悟空",500);
        Person two=new Person("悟能",400);
        Person three=new Person("悟净",300);

        arr[0]=one;//将one当中的’地址值‘赋值到数组的0号元素位置
        arr[1]=two;
        arr[2]=three;
        System.out.println(arr[2].getName());

        ArrayList<Person> l=new ArrayList<>();
        l.add(one);
        l.add(two);
        l.add(three);

        for (int i = 0; i <l.size(); i++) {
            Person p=l.get(i);
            System.out.print(p.getName()+p.getAge());
        }


    }


}

class Person{

    private String name;
    private int age;

    public Person() {
        System.out.println("无参构造函数");
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("全参构造函数");
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
